<template>
	<view class="wrap">
		<view class="search">
			<input @input="getvalue" class="serch-inp" type="text" placeholder="搜索商品">
			<view class="serch-test" @click="GoSearch">搜索</view>
		</view>

		<uni-grid v-if="productsList.length==0" :column="3" :showBorder="false" :square="false">
			<uni-grid-item class="words" v-for="(item,index) in Lists" :key="index">
				<view @click="Godes(item)">{{item}}
				</view>
			</uni-grid-item>
		</uni-grid>

		<uni-grid v-else :column="2" :showBorder="false" :square="false">
			<uni-grid-item class="lisitem" v-for="(item,index) in productsList" :key="index">
				<view @click="Godetails(item.bh)">
					<image class="img" :src="item.xhtp" mode=""></image>
					<view class="text">{{item.xhmc}}</view>
					<view class="bottom">
						<view class="price">￥{{item.xhyjjg}}</view>
						<view class="sum">已销售{{ite.xhxl}}件</view>
					</view>
				</view>
			</uni-grid-item>
		</uni-grid>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: '',
				productsList: [],
				Lists: ['玫瑰', '情侣'] 

			}
		}, 
		methods: {
			Godes(item) {
				this.inputValue = item
				this.GoSearch()
				 
			},
			GoSearch() {  
				this.requestfs({
					url: '/mall/goods/selectSearchList?name=' + this.inputValue
				}).then(res => {
					this.show = false
					if (res.data.msg == "success") {
						this.productsList = res.data.data
						if (this.productsList.length == 0) {
							 
							uni.showToast({
								title: '糟糕，找不到呀~',
								icon: 'none'
							})
						}
					}
				})
			},
			getvalue(e) {
				this.inputValue = e.target.value
			},

		}
	}
</script>

<style lang="scss">
	.wrap {
		background: #f3f5f7;
		min-height: 100vh;
		height: auto;
		width: 750rpx;
		padding-top: 20rpx;

		.search {
			width: 724rpx;
			margin: 0 13rpx;
			border: 2px solid #ef5e25;
			border-radius: 50rpx;
			display: flex;
			margin-bottom: 20rpx;

			.serch-inp {
				width: 71.5%;
				height: 60rpx;
				padding-left: 10%;
				color: #c4c3c3;
				font-size: 28rpx;
			}

			.serch-test {
				width: 18%;
				background-image: linear-gradient(to right, rgba(237, 127, 48, 0.8), rgba(236, 96, 45, 1));
				color: #ffffff;
				height: 56rpx;
				line-height: 56rpx;
				border-radius: 50rpx;
				text-align: center;
				margin-top: 2rpx;
				font-size: 26rpx;
			}
		}

		.lisitem {
			background: #ffffff;
			width: 46%;
			margin: 0 2% 20rpx 2%;
			border-radius: 10rpx;

			.bottom {
				margin: 0 10rpx 10rpx 10rpx;

				.price {
					width: 50%;
					color: #ef5e25;
					font-weight: bold;
				}

				.sum {
					font-size: 22rpx;
					margin-top: 6rpx;
					color: #71797f;
				}
			}

			.text {
				line-height: 40rpx;
				font-size: 28rpx;
				margin: 10rpx;
				padding: 0 6rpx 0 2rpx;
				overflow: hidden; //超出部分隐藏
				text-overflow: ellipsis; //文字隐藏部分显示省略号
				display: -webkit-box; //改变盒子模型
				-webkit-line-clamp: 1; //文字显示几行
				-webkit-box-orient: vertical;
			}

			.img {
				width: 92%;
				height: 350rpx;
				border-radius: 10rpx;
			}
		}

		.words {
			width: 42%;
			color: #333;
			background-color: #fff;
			margin: 10rpx auto;
			height: 66rpx;
			line-height: 66rpx;
			padding-left: 20rpx;
		}
	}
</style>
